package leetcode.t2String;

import java.util.HashMap;

/**
 * @author K
 * @date 2024/1/23 14:34
 */
public class T0_StringSolution {

    public static int lengthOfLongestSubstring(String s) {
        int result =0,left = 0;
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.toCharArray().length; i++) {
            char c = s.charAt(i);
            if (map.containsKey(c)){
                left = Math.max(left, map.get(c) +1);
            }
            map.put(c, i);
            result = Math.max(result, i-left+1);
        }

        return result;
    }

    public static void main(String[] args) {
        int result = lengthOfLongestSubstring("abcabcbb");
        int result1 = lengthOfLongestSubstring("bbbbb");
        int result2 = lengthOfLongestSubstring("pwwkew");
        int result3 = lengthOfLongestSubstring("a");
        System.out.println();
    }

}
